package net.profo.infoplayas;

import java.util.ArrayList;
import java.util.List;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import android.app.Activity;
import android.os.Bundle;
import android.util.Xml;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.TextView;

public class InfoPlayasDroid extends Activity 
{
	TextView tvPlaya;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        tvPlaya = (TextView)findViewById(R.id.txtPlayas);
        
        //call();
        setMunicipios();
    }
    
    public void setMunicipios()
    {
    	try
    	{
    		MunicipioParser parser = new MunicipioParser();
            
            List<Municipio> municipios = parser.parse();
         
            //Leemos
            List<String> titles = new ArrayList<String>(municipios.size());
            
            for (Municipio munic : municipios) 
            {
    			titles.add(munic.getNombre());
    		}
            
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.row, titles);
            
            ListView lstOpciones = (ListView)findViewById(R.id.LstOpciones);
            
            lstOpciones.setAdapter(adapter);
            
            /*final Spinner cmbOpciones = (Spinner)findViewById(R.id.CmbOpciones);
            
            ArrayAdapter<String> adaptador = new ArrayAdapter<String>(this,
                    android.R.layout.simple_list_item_1, titles);
            
            adaptador.setDropDownViewResource(
                    android.R.layout.simple_spinner_dropdown_item);
            
            cmbOpciones.setAdapter(adaptador);*/
    	}
    	catch(Exception e)
    	{
    		tvPlaya.setText(e.getMessage());
    	}
    }
    
    public void call()
    {
    	try
    	{
    		PlayaParser parser = new PlayaParser();
            
            List<Playa> playas = parser.parse();
         
            //Leemos
            List<String> titles = new ArrayList<String>(playas.size());
            
            for (Playa playa : playas) 
            {
    			titles.add(playa.getAnchura());
    		}
            
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.row, titles);
            
            ListView lstOpciones = (ListView)findViewById(R.id.LstOpciones);
            
            lstOpciones.setAdapter(adapter);
            
            
    	}
    	catch(Exception e)
    	{
    		tvPlaya.setText(e.getMessage());
    	}
    }
}